package com.sh.rbac.core.encrypt.encryptor;

import com.sh.rbac.core.encrypt.enums.EncodeType;
import com.sh.rbac.core.encrypt.util.EncryptUtils;

/**
 * sm2 加密器
 *
 * @author wb
 * @since 2025-10-24
 */
public class Sm2Encryptor implements IEncryptor {
    @Override
    public String encrypt(EncryptContext context) {
        String value = context.getValue();
        String publicKey = context.getPublicKey();

        if (context.getEncodeType() == EncodeType.HEX) {
            return EncryptUtils.encryptBySm2Hex(value, publicKey);
        }

        return EncryptUtils.encryptBySm2(value, publicKey);
    }

    @Override
    public String decrypt(EncryptContext context) {
        return EncryptUtils.decryptBySm2(context.getValue(), context.getPrivateKey());
    }
}
